//
//  CommonTool.m
//  新闻类APP
//
//  Created by 爱生活Geek on 16/10/7.
//  Copyright © 2016年 爱生活. All rights reserved.
//

#import "CommonTool.h"

@implementation CommonTool

+ (NSString *)currentTimePsw:(NSDate *)currentDate;
{
    NSDateFormatter *dateFormatter  = [[NSDateFormatter alloc] init];
    
    dateFormatter.dateFormat = @"yyyy-MM-dd HH:mm:ss";
    
    NSTimeInterval time = (long)[currentDate timeIntervalSince1970] + 31;
    
    //将时间戳转换成字符串
    NSDate *dt = [NSDate dateWithTimeIntervalSince1970:time];
    
    NSDateFormatter *df = [[NSDateFormatter alloc] init];
    
    df.dateFormat = @"yyyy-MM-dd HH:mm:ss";
    
    return [df stringFromDate:dt];
}
+ (NSString *)currentTime:(NSDate *)currentDate
{
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    [dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
    NSString *destDateString = [dateFormatter stringFromDate:currentDate];
    
    return destDateString;
}
+ (UIColor *)randomColor
{
    CGFloat hue = ( arc4random() % 256 / 256.0 );  //  0.0 to 1.0
    
    CGFloat saturation = ( arc4random() % 128 / 256.0 ) + 0.5;  //  0.5 to 1.0, away from white
    CGFloat brightness = ( arc4random() % 128 / 256.0 ) + 0.5;  //  0.5 to 1.0, away from black
    return [UIColor colorWithHue:hue saturation:saturation brightness:brightness alpha:1];
}
+ (NSString *)timeWithUTC:(int)sunStr
{
    NSString *temp = [NSString stringWithFormat:@"%d",sunStr];
    
    NSTimeInterval timer = temp.doubleValue;
    
    NSDate *date = [NSDate dateWithTimeIntervalSince1970:timer];
    
    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];

    formatter.dateFormat = @"yyyy-MM-dd     HH-mm";
    
    return [formatter stringFromDate:date];
}
+ (NSMutableAttributedString *)setLabelGapWithStr:(NSString *)labelStr andGap:(float)gamNum
{
    //设置行间距
    NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:labelStr];
    
    NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
    
    [paragraphStyle setLineSpacing:gamNum];//调整行间距
    
    [attributedString addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, [labelStr length])];

    return attributedString;
}
@end
